﻿using System;
using System.Web;

namespace DotNet.Utilities
{
    /// <summary>
    /// 提供缓存机制的公共类
    /// </summary>
    public class CacheUtil
    {
        /// <summary>
        /// 设置一个缓存（默认10分钟）
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void Put(string key, object value)
        {
            Put(key, value, 10);
        }
        /// <summary>
        /// 设置一个缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="minutes">N分钟后移除</param>
        public static void Put(string key, object value, int minutes)
        {
            HttpRuntime.Cache.Insert(key, value, null, DateTime.Now.AddMinutes(Convert.ToDouble(minutes)), TimeSpan.Zero);
        }

        public static object Get(string key)
        {
            return HttpRuntime.Cache.Get(key);
        }

        public static void Remove(string key)
        {
            HttpRuntime.Cache.Remove(key);
        }
    }
}
